package stringTest;

public class StringDemoTest {
    public static void main(String[] args) {
        //.length()
        String str="我爱Java";
        int len=str.length();
        System.out.println(len);
        System.out.println(str.codePointCount(0,str.length()));
        System.out.println("__________________");
        //.trim()
        String str2="   我爱Java   ";
        System.out.println(str2.trim());
        System.out.println("__________________");
        //.toUpperCase()/.toLowerCase()
        String str3="我爱Java";
        System.out.println(str3.toUpperCase());
        System.out.println(str3.toLowerCase());
        System.out.println("__________________");
        //.startsWith()/.endsWith()
        //判断字符串是否以指定的字符串开头或结尾
        String str4="我爱Java";
        System.out.println(str4.startsWith("我"));//true
        System.out.println(str4.endsWith("Java"));//true
        System.out.println("__________________");
        //.charAt()
        //获取指定索引处的字符
        String str5="我爱Java";
        System.out.println(str5.charAt(0));
        System.out.println("__________________-");
        //indexOf()/.lastIndexOf()
        //获取指定字符串在字符串中第一次出现的索引位置
        String str6="我爱Java";
        System.out.println(str6.indexOf("我"));
        System.out.println(str6.lastIndexOf("我"));
        System.out.println("_________________________");
        //.substring()
        //获取指定索引范围的子字符串
        String str7="我爱Java";
        System.out.println(str7.substring(0,2));
        System.out.println("_________________________");
        //.valueOf() 静态方法
        //将其它数据类型转换为字符串
        int num=100;
        System.out.println(String.valueOf(num));
        System.out.println("_________________________");
        //.equals()/.equalsIgnoreCase()
        //比较两个字符串是否相等
        String str8="我爱Java";
        String str9="我爱Java";
        System.out.println(str8.equals(str9));
        System.out.println(str8.equalsIgnoreCase(str9));
        System.out.println("_________________________");
        //StringBuilder
        //append():添加字符串,在末尾加
        StringBuilder sb=new StringBuilder("我爱Java");
        sb.append("!");
        System.out.println(sb);
        System.out.println("____________________________");
        //delect():删除指定索引范围的子字符串
        StringBuilder builder=new StringBuilder("我爱Java");
        builder.delete(0,2);
        System.out.println(builder);
        System.out.println("____________________________");
        //replace():替换指定索引范围的子字符串
        StringBuilder builder2=new StringBuilder("我爱Java");
        builder2.replace(0,2,"我");
        System.out.println(builder2);
        System.out.println("____________________________");
        //insert():在指定索引处插入字符串
        StringBuilder builder3=new StringBuilder("我爱Java");
        builder3.insert(0,"我,");
        System.out.println(builder3);



    }

}
